package controllers

import (
	"airserver/airmodel"

	"github.com/astaxie/beego"
)

type HisController struct {
	beego.Controller
}

func (c *HisController) Get() {
	mn := c.GetString("mn")
	code := c.GetString("code")
	// datatype := c.GetString("datatype")
	typei, err := c.GetInt("type")
	pagenum, err := c.GetInt("pagenum")
	if nil != err {
		pagenum = 1
	} else {
		if pagenum < 1 {
			pagenum = 1
		}
	}

	var all int64
	if typei == 1 {
		num, hd, allhd := airmodel.GetMinData(mn, code, pagenum)
		c.Data["HisNum"] = num
		c.Data["HisData"] = hd
		all = allhd
	} else if typei == 2 {
		num, hd, allhd := airmodel.GetHourData(mn, code, pagenum)
		c.Data["HisNum"] = num
		c.Data["HisData"] = hd
		all = allhd
	} else if typei == 3 {
		num, hd, allhd := airmodel.GetDayData(mn, code, pagenum)
		c.Data["HisNum"] = num
		c.Data["HisData"] = hd
		all = allhd
	}
	if all%100 == 0 {
		all = all / 100
	} else {
		all = all/100 + 1
	}
	c.Data["HisType"] = typei
	c.Data["HisMn"] = mn
	c.Data["HisCode"] = code
	c.Data["PageNum"] = pagenum
	c.Data["PageAll"] = all
	c.TplName = "his.html"
}
